home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk21 / pelihack / trails.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  5KB  |  263 lines

  1. /* Trails, by Oren Peli, Copyright (c) 1988 BazboSoft! */
  2.  
  3. #include <graphics/gels.h>
  4. #include <hardware/cia.h>
  5.  
  6. void *OpenLibrary();
  7.  
  8. struct IntuitionBase *IntuitionBase = NULL;
  9. struct GfxBase *GfxBase = NULL;
  10.  
  11. struct Screen *OpenWorkBench();
  12.  
  13. struct Screen *scr;
  14.  
  15. PLANEPTR pln[4];
  16.  
  17. PLANEPTR AllocRaster();
  18.  
  19. struct BitMap *bm;
  20.  
  21. WORD olddepthglob , newdepthglob;
  22.  
  23. WORD pointer_data0[16 * 2 * 3] = { 0 };
  24. WORD *pointer_data1;
  25. WORD *pointer_data2;
  26.  
  27. WORD is[16 * 2] = { 0 };
  28.  
  29. WORD bl[4] = { 0 };
  30.  
  31. struct RastPort trp;
  32. struct BitMap tbm;
  33.  
  34. struct VSprite vs;
  35. struct VSprite dummyhead , dummytail;
  36. struct Bob bob;
  37. struct GelsInfo gi;
  38.  
  39. WORD bob_added = NULL;
  40.  
  41. main()
  42. {
  43.     REGISTER WORD olddepth , t , i;
  44.  
  45.     REGISTER struct ViewPort *vp;
  46.  
  47.     REGISTER struct Preferences prefs;
  48.  
  49.     pointer_data1 = pointer_data0 + 16 * 2;
  50.     pointer_data2 = pointer_data1 + 16 * 2;
  51.  
  52.     pln[0] = pln[1] = pln[2] = pln[3] = NULL;
  53.  
  54.     puts("Trails, by Oren Peli, Copyright (c) 1988 BazboSoft!\nMove the mouse. The left mouse button will clear the screen.\n\nPress CTRL-C to abort (or use 'Break').");
  55.  
  56.     if (NOT (IntuitionBase = OpenLibrary("intuition.library" , 33L) ) )
  57.         bye();
  58.  
  59.     if (NOT (GfxBase = OpenLibrary("graphics.library" , 33L) ) )
  60.         bye();
  61.  
  62.     GetPrefs(&prefs , (LONG) sizeof(struct Preferences) );
  63.  
  64.     InitBitMap(&tbm , 3L , 32L , 16L);
  65.  
  66.     InitRastPort(&trp);
  67.  
  68.     trp.BitMap = &tbm;
  69.  
  70.     setmem(pointer_data0 , 16 * 2 , 0);
  71.     setmem(pointer_data1 , 16 * 2 , 0);
  72.     setmem(pointer_data2 , 16 * 2 , 0);
  73.  
  74.     for (i = 0 ; i != 16 ; i++)
  75.     {
  76.         pointer_data0[i * 2] = prefs.PointerMatrix[i * 2];
  77.         pointer_data1[i * 2] = prefs.PointerMatrix[i * 2 + 1];
  78.         pointer_data2[i * 2] = pointer_data0[i * 2] | pointer_data1[i * 2];
  79.     }
  80.  
  81.     scr = OpenWorkBench();
  82.  
  83.     bm = scr->ViewPort.RasInfo->BitMap;
  84.  
  85.     tbm.Planes[0] = (PLANEPTR) pointer_data0;
  86.     tbm.Planes[1] = (PLANEPTR) pointer_data1;
  87.     tbm.Planes[2] = (PLANEPTR) pointer_data2;
  88.  
  89.     olddepth = bm->Depth;
  90.  
  91.     if (3 > olddepth)
  92.     {
  93.         if (NOT alloc_planes(olddepth , 3 , scr->Width , scr->Height) )
  94.         {
  95.             puts("Not enough memory!");
  96.  
  97.             bye();
  98.         }
  99.     }
  100.  
  101.     newdepthglob = 3;
  102.     olddepthglob = olddepth;
  103.  
  104.     vp = & scr->ViewPort;
  105.  
  106.     t = GetRGB4(vp->ColorMap , 16L);
  107.     SetRGB4(vp , 4L , (LONG) t >> 8L , (LONG) ( (t & 0x0f0L) >> 4L) , (LONG) t &
  108.                                                                                 0x00fL);
  109.  
  110.     t = GetRGB4(vp->ColorMap , 17L);
  111.     SetRGB4(vp , 5L , (LONG) t >> 8L , (LONG) ( (t & 0x0f0L) >> 4L) , (LONG) t &
  112.                                                                                 0x00fL);
  113.  
  114.     t = GetRGB4(vp->ColorMap , 18L);
  115.     SetRGB4(vp , 6L , (LONG) t >> 8L , (LONG) ( (t & 0x0f0L) >> 4L) , (LONG) t &
  116.                                                                                 0x00fL);
  117.  
  118.     t = GetRGB4(vp->ColorMap , 19L);
  119.     SetRGB4(vp , 7L , (LONG) t >> 8L , (LONG) ( (t & 0x0f0L) >> 4L) , (LONG) t &
  120.                                                                                 0x00fL);
  121.  
  122.     for (i = 15 ; i >= 0 ; i--)
  123.     {
  124.         ClipBlit(&trp , (LONG) i , 0L , &trp , (LONG) i * 2L , 0L , 1L , 16L , 0xC0L);
  125.  
  126.         ClipBlit(&trp , (LONG) i , 0L , &trp , (LONG) i * 2L + 1L , 0L , 1L , 16L ,
  127.                                                                                 0xC0L);
  128.     }
  129.  
  130.     InitGels(&dummyhead , &dummytail , &gi);
  131.  
  132.     scr->RastPort.GelsInfo = &gi;
  133.  
  134.     vs.Height = 16;
  135.     vs.VSBob = &bob;
  136.     vs.Width = 2;
  137.     vs.Depth = 3;
  138.     vs.ImageData = pointer_data0;
  139.     vs.Flags = OVERLAY;
  140.     vs.X = 0;
  141.     vs.Y = 0;
  142.  
  143.     bob.BobVSprite = &vs;
  144.  
  145.     vs.PlaneOnOff = 7;
  146.     vs.PlanePick = 7;
  147.  
  148.     bob.ImageShadow = is;
  149.  
  150.     bob.DBuffer = NULL;
  151.     bob.SaveBuffer = NULL;
  152.  
  153.     bob.Before = NULL;
  154.     bob.After = NULL;
  155.  
  156.     vs.BorderLine = bl;
  157.     vs.CollMask = is;
  158.  
  159.     InitMasks(&vs);
  160.  
  161.     AddBob(&bob , &scr->RastPort);
  162.  
  163.     bob_added = 1;
  164.  
  165.     for (;;)
  166.     {
  167.         vs.X = scr->MouseX + prefs.XOffset * 2L + 2L;
  168.         vs.Y = scr->MouseY + prefs.YOffset - 1L;
  169.  
  170.         SortGList(&scr->RastPort);
  171.  
  172.         DrawGList(&scr->RastPort , &scr->ViewPort);
  173.  
  174.         Chk_Abort();
  175.  
  176.         if (NOT (ciaa.ciapra & 64) )
  177.             puts(" ");
  178.     }
  179. }
  180.  
  181. _abort()
  182. {
  183.     if (bob_added)
  184.         RemIBob(&bob , &scr->RastPort , &scr->ViewPort);
  185.  
  186.     delete_planes(newdepthglob , olddepthglob , scr->Width , scr->Height);
  187.  
  188.     puts(" ");
  189.  
  190.     bye();
  191. }
  192.  
  193. alloc_planes(olddepth , newdepth , width , height)
  194. register int olddepth , newdepth , width , height;
  195. {
  196.     register int i;
  197.  
  198.     Forbid();
  199.  
  200.     for (i = olddepth ; i != newdepth ; i++)
  201.         if (NOT (pln[i] = AllocRaster( (long) width , (long) height) ) )
  202.         {
  203.             Permit();
  204.  
  205.             return(NULL);
  206.         }
  207.  
  208.         else
  209.         {
  210.             BltClear(pln[i] , (long) RASSIZE(width , height) , NULL);
  211.  
  212.             bm->Planes[i] = pln[i];
  213.         }
  214.  
  215.     bm->Depth = newdepth;
  216.  
  217.     Permit();
  218.  
  219.     MakeScreen(scr);
  220.  
  221.     RethinkDisplay();
  222.  
  223.     return(1);
  224. }
  225.  
  226. delete_planes(olddepth , newdepth , width , height)
  227. register int olddepth , newdepth , width , height;
  228. {
  229.     register int i;
  230.  
  231.     Forbid();
  232.  
  233.     for (i = newdepth ; i != olddepth ; i++)
  234.     {
  235.         FreeRaster(bm->Planes[i] , (long) width , (long) height);
  236.  
  237.         bm->Planes[i] = NULL;
  238.     }
  239.  
  240.     bm->Depth = newdepth;
  241.  
  242.     Permit();
  243.  
  244.     MakeScreen(scr);
  245.  
  246.     RethinkDisplay();
  247.  
  248.     return(1);
  249. }
  250.  
  251. bye()
  252. {
  253.     register int i , width = scr->Width , height = scr->Height;
  254.  
  255.     if (IntuitionBase)
  256.         CloseLibrary(IntuitionBase);
  257.  
  258.     if (GfxBase)
  259.         CloseLibrary(GfxBase);
  260.  
  261.     exit(0);
  262. }
  263.